package com.test.socket;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Date;

import cn.zniot.so.application.constant.Constants;

public class Client {
	private int id;

	public Client() {
	}

	public Client(int id) {
		super();
		this.id = id;
	}

	public static void main(String[] args) {
		for (int i = 0; i < 60000; i++) {
			Client c = new Client(i);
			c.test();
		}
		System.out
				.println("-------------------------------------------------- game over-----------------------------------------------");
	}

	public void test() {
		new Thread() {
			public void run() {
				System.out
						.println(id
								+ "   -------------------------0000000000000000000000000000000000000----------------------------------------");
				// =====================================================
				String host = "115.47.55.5";
				int port = 6950;
				try {
					Socket s = new Socket(host, port);
					s.setSoTimeout(10 * 1000);
					OutputStream os = s.getOutputStream();
					InputStream is = s.getInputStream();
					String packages = "#Ai+333," + this.getId() + ",Fir,B" + this.getId() + "!";
					os.write(packages.getBytes());
					os.flush();
					while (true) {
						Date current = new Date();
						if (current.getSeconds() / 10 == 0) {
							os.write(Constants.HEART_BEAT_DOWN);
							os.flush();
							System.out.println(id + " ========ok======" + current.getSeconds() + " ===  " + is.read());
						}

						// System.out.println(is.read());
					}
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}.start();
	}
}
